package com.github.soiff.shadow.plugin.helper;

import com.github.jknack.handlebars.Helper;
import com.github.jknack.handlebars.Options;

import java.io.IOException;
import java.util.Collection;
import java.util.Map;

/**
 * Created by Soiff on 2016/05/20.
 *
 * @author : Soiff
 */
public class SizeHelper implements Helper {
    @Override
    public CharSequence apply(Object context, Options options) throws IOException {
        return context == null?"0":(context instanceof Collection ?String.valueOf(((Collection)context).size()):(context instanceof Map ?String.valueOf(((Map)context).size()):"0"));
    }
}
